import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int[] array={1,2,3,4,5,6,7};
        quickSort(array);
        System.out.println(Arrays.toString(array));
    }

    private static void quickSort(int[] array) {
        int n = array.length;
        quickSort1(array,0,n-1);
    }

    private static void quickSort1(int[] array, int left, int right) {
        if(left>=right)
             return ;
        int pivot = partition(array,left,right);
        quickSort1(array,left,pivot-1);
        quickSort1(array,pivot+1,right);
    }

    private static int partition(int[] array, int left, int right) {
        int i =left;
        int key = array[left];
        while(left<right){
            while(left<right&&array[right]<=key){
                right--;
            }
            while(left<right&&array[left]>=key){
                left++;
            }
            swap(array,left,right);
        }
        swap(array,i,left);
        return left;
    }

    private static void swap(int[] array, int left, int right) {
        int tmp = array[left];
        array[left] = array[right];
        array[right] = tmp;
    }
}